package com.baiqi.rabbitmq.rabbitmq.helloworld;

import com.baiqi.rabbitmq.rabbitmq.utils.RabbitConstant;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");
        connectionFactory.setVirtualHost("/");

        Connection connection = connectionFactory.newConnection();

        Channel channel = connection.createChannel();

        channel.queueDeclare(RabbitConstant.QUEUE_HELLOWORLD,false,false,false,null);

        String message= "hello白起666";

        channel.basicPublish("",RabbitConstant.QUEUE_HELLOWORLD,null,message.getBytes(StandardCharsets.UTF_8));
        channel.close();
        connection.close();
        System.out.println("===发送成功===");
    }
}
